home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 November
/
EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso
/
earcd
/
util
/
text
/
strip11.lzh
/
Strip.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-27
|
2KB
|
105 lines
/***************************
* Strip $Revision: 1.1 $ *
* (C) 1995 Simon Austin *
***************************/
/* $Id: Strip.c,v 1.1 1995/03/23 16:32:16 simon Exp simon $ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
char *version="$VER: Strip (C)1995 S Austin $Revision: 1.1 $";
char *errorcl="Usage: Strip [Infile] [Outfile]\n";
char infilename[50], outfilename[50];
char inchar, outchar;
FILE *infile, *outfile;
void filefail(char *);
main(int argc, char *argv[])
{
if(argc < 1 || argc > 3)
{
/* between none and two options are allowed on the command line */
fputs(errorcl, stderr);
exit(0);
}
/* Set filenames to - so uses stdin/stdout unless redirected */
strcpy(infilename, "-");
strcpy(outfilename, "-");
if(argc == 2)
{
/* One option: get name of infile */
strcpy(infilename, argv[1]);
}
if(argc == 3)
{
/* Two options: get names of in and out files */
strcpy(infilename, argv[1]);
strcpy(outfilename, argv[2]);
if(!strcmp(infilename, outfilename) && strcmp(infilename, "-"))
strcat(outfilename, ".str");
}
/* Set file pointers to stdin/stdout. They'll be set otherwise if required */
infile = stdin;
outfile = stdout;
/* If the input filename is not -, try and open the file */
if(strcmp(infilename, "-"))
{
infile = fopen(infilename, "r");
if(!infile)
{
filefail(infilename);
}
}
if(strcmp(outfilename, "-"))
{
outfile = fopen(outfilename, "w");
if(!outfile)
{
filefail(outfilename);
}
}
outchar = ' ';
inchar = fgetc(infile);
while(inchar != EOF && outchar != EOF)
{
if(isprint(inchar))
outchar = fputc(inchar, outfile);
if(inchar == '\n' || inchar == '\t')
outchar = fputc(inchar, outfile);
inchar = fgetc(infile);
}
if(outchar == EOF)
{
fputs("Error in \"", stderr);
fputs(outfilename, stderr);
fputs("\".\n", stderr);
}
if(strcmp(infilename, "-"))
fclose(infile);
if(strcmp(outfilename, "-"))
fclose(outfile);
exit(0);
}
void filefail(char *filename)
{
fputs("Cannot open \"", stderr);
fputs(filename, stderr);
fputs("\".\n", stderr);
exit(0);
}